<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="机器学习启蒙,">










<meta name="description" content="本文为慕课网《机器学习启蒙》的第一章，主要讲解：机器学习概述">
<meta name="keywords" content="机器学习启蒙">
<meta property="og:type" content="article">
<meta property="og:title" content="【第一章】机器学习启蒙——机器学习概述">
<meta property="og:url" content="https://aiolos123.gitee.io/blog/2019/10/11/machine-learning-step-by-step-1/index.html">
<meta property="og:site_name" content="Aiolos">
<meta property="og:description" content="本文为慕课网《机器学习启蒙》的第一章，主要讲解：机器学习概述">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012120323925.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191011172541006.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191011172607972.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191011172716837.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191011172749154.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191011172807038.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191011172838202.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012054639825.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012060754363.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012085355741.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012085630822.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012085704712.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012095712503.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012115454851.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012120323925.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012104814954.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012110908795.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012111219555.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012111925890.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012115454851.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012115641820.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012115957375.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012124505697.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012120214550.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012124949811.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012130016458.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012063817663.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012063951164.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012134839062.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012135207409.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012140111818.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012140716113.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012142219785.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191012142348128.jpg">
<meta property="og:updated_time" content="2019-10-12T06:24:00.018Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【第一章】机器学习启蒙——机器学习概述">
<meta name="twitter:description" content="本文为慕课网《机器学习启蒙》的第一章，主要讲解：机器学习概述">
<meta name="twitter:image" content="https://aiolos123.gitee.io/blog/images/20191012120323925.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://aiolos123.gitee.io/blog/2019/10/11/machine-learning-step-by-step-1/">





  <title>【第一章】机器学习启蒙——机器学习概述 | Aiolos</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Aiolos</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录我的成长点滴</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://aiolos123.gitee.io/blog/blog/2019/10/11/machine-learning-step-by-step-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="aiolos">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Aiolos">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">【第一章】机器学习启蒙——机器学习概述</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-10-11T05:59:13+08:00">
                2019-10-11
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/机器学习/" itemprop="url" rel="index">
                    <span itemprop="name">机器学习</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本文为慕课网《机器学习启蒙》的第一章，主要讲解：机器学习概述</p>
<a id="more"></a>

<p><strong>安装GraphLab Create成功后，直接通过如下方式即可启动GraphLab Create</strong><br><img src="/blog/images/20191012120323925.jpg" alt="启动GraphLab Create"></p>
<h2 id="课程介绍"><a href="#课程介绍" class="headerlink" title="课程介绍"></a>课程介绍</h2><blockquote>
<p>以Python为主讲语言并通过真实案例让你快速入门机器学习。课程仅为基础教程适合于无任何基础的学员可以通过本教程很好的学习机器学习并快速入门。建议你在学习之前对Python的语法进行了解毕竟在人工智能领域Python作为主力语言还是非常有必要掌握的。课程基于Python机器学习库并且包含相对较为完善的资料和机器算法操作便捷的同时提供高效的数据挖掘与分析。所以这套课程是相当适合作为机器学习的入门课程。</p>
</blockquote>
<p><strong>课程对象： 机器学习0基础的小白</strong><br>课程特点：通过实际案例入手，从实际案例引入模型和算法</p>
<h2 id="教学方法"><a href="#教学方法" class="headerlink" title="教学方法"></a>教学方法</h2><blockquote>
<p>理论 + 实战项目</p>
</blockquote>
<p><img src="/blog/images/20191011172541006.jpg" alt="教学方法"></p>
<h2 id="机器学习管道"><a href="#机器学习管道" class="headerlink" title="机器学习管道"></a>机器学习管道</h2><p>本课程学习机器学习的方法：机器学习管道</p>
<blockquote>
<p>数据  ==&gt; 机器学习算法 ==&gt; 智能应用</p>
</blockquote>
<h2 id="课程内容"><a href="#课程内容" class="headerlink" title="课程内容"></a>课程内容</h2><ol>
<li><p>回归模型<br><img src="/blog/images/20191011172607972.jpg" alt="回归模型"></p>
</li>
<li><p>分类模型<br><img src="/blog/images/20191011172716837.jpg" alt="分类模型"></p>
</li>
<li><p>聚合类相似度模型<br><img src="/blog/images/20191011172749154.jpg" alt="聚合类相似度模型"></p>
</li>
<li><p>推荐系统<br><img src="/blog/images/20191011172807038.jpg" alt="推荐系统"></p>
</li>
<li><p>深度学习<br><img src="/blog/images/20191011172838202.jpg" alt="深度学习"></p>
</li>
</ol>
<h2 id="机器学习的应用"><a href="#机器学习的应用" class="headerlink" title="机器学习的应用"></a>机器学习的应用</h2><p><img src="/blog/images/20191012054639825.jpg" alt="机器学习的应用"></p>
<h2 id="GraphLab-Create的安装"><a href="#GraphLab-Create的安装" class="headerlink" title="GraphLab Create的安装"></a>GraphLab Create的安装</h2><blockquote>
<p>GraphLab Create 是一款机器学习的函数库，其中的SFrame也是十分强大的数据管理工具。它允许直接从硬盘中读取数据，免于将数据全部加载到内存中。这就使得对于大数据的处理成为可能.这也是相对于scikit-learn的一个最大优点,我们知道,scikit-learn是只能读取内存中的数据</p>
</blockquote>
<blockquote>
<p>GraphLab Create官网：<a href="https://turi.com/" target="_blank" rel="noopener">https://turi.com/</a></p>
</blockquote>
<ol>
<li><p>下载安装包<br><img src="/blog/images/20191012060754363.jpg" alt="下载安装包"></p>
</li>
<li><p>从上述地址申请学术许可academic license (免费的)</p>
</li>
<li><p>双击安装包，启动GraphLab Create Launcher,输入academic license后点击next<br><img src="/blog/images/20191012085355741.jpg" alt="启动GraphLab Create Launcher"></p>
</li>
<li><p>点击next，开始安装Anaconda等<br><img src="/blog/images/20191012085630822.jpg" alt="开始安装"><br><img src="/blog/images/20191012085704712.jpg" alt="开始安装"></p>
</li>
<li><p>如果出现错误，按照错误提示解决，如下图为本人安装过程中出现的错误:</p>
<blockquote>
<p>按照提示解决错误后，重启GraphLab Create Launcher再进行安装</p>
</blockquote>
</li>
</ol>
<p><img src="/blog/images/20191012095712503.jpg" alt="安装出现错误"></p>
<ol start="6">
<li>启动Notebook开发环境<br>启动Notebook后出现如下界面，说明安装成功<br><img src="/blog/images/20191012115454851.jpg" alt="启动Notebook"></li>
</ol>
<ol start="7">
<li><strong>安装GraphLab Create成功后，直接通过如下方式即可启动GraphLab Create</strong><br><img src="/blog/images/20191012120323925.jpg" alt="启动GraphLab Create"></li>
</ol>
<h3 id="出现Error-environment-does-not-exist错误的安装方法"><a href="#出现Error-environment-does-not-exist错误的安装方法" class="headerlink" title="出现Error: environment does not exist错误的安装方法"></a>出现Error: environment does not exist错误的安装方法</h3><p>使用GraphLab Create Launcher进行安装，如果出现如下图的错误，则需要按照如下步骤进行安装<br>错误原因：虚拟环境未创建成功<br>解决办法：使用命令行的方式手动创建虚拟环境并完成安装<br><strong>注意：一定不能再启动GraphLab Create Launcher进行安装</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 手动创建虚拟环境</span></span><br><span class="line">conda <span class="keyword">create</span> -n gl-env python=<span class="number">2.7</span> anaconda</span><br><span class="line"><span class="comment"># 使用如下命令完成安装</span></span><br><span class="line"><span class="keyword">activate</span> gl-env <span class="comment"># 启动虚拟环境</span></span><br><span class="line">CD anaconda2/envs/gl-env/</span><br><span class="line">conda <span class="keyword">install</span> pip <span class="keyword">or</span> conda <span class="keyword">update</span> pip <span class="comment"># 更新pip</span></span><br><span class="line"><span class="comment"># 安装GraphLab Create</span></span><br><span class="line">pip <span class="keyword">install</span> <span class="comment">--upgrade --no-cache-dir https://get.graphlab.com/GraphLab-Create/2.1/注册邮箱地址/注册的product key/GraphLab-Create-License.tar.gz</span></span><br><span class="line"><span class="comment"># 安装IPython and IPython Notebook</span></span><br><span class="line">conda <span class="keyword">install</span> ipython-notebook</span><br><span class="line"><span class="comment"># 启动Notebook</span></span><br><span class="line">ipython notebook</span><br></pre></td></tr></table></figure>

<p>错误界面与解决过程如下图：<br><img src="/blog/images/20191012104814954.jpg" alt="environment does not exist"></p>
<p>安装过程如下图：<br><img src="/blog/images/20191012110908795.jpg" alt="安装过程"><br><img src="/blog/images/20191012111219555.jpg" alt="安装过程"><br><img src="/blog/images/20191012111925890.jpg" alt="安装过程"></p>
<p>启动Notebook后出现如下界面，说明安装成功<br><img src="/blog/images/20191012115454851.jpg" alt="启动Notebook"></p>
<h3 id="import-graphlab错误"><a href="#import-graphlab错误" class="headerlink" title="import graphlab错误"></a>import graphlab错误</h3><p>当import graphlab时，如果出现如下错误：<br><img src="/blog/images/20191012115641820.jpg" alt="import graphlab错误"></p>
<p>解决方法见上图，执行步骤如下图：</p>
<ol>
<li>设置文件夹权限<br><img src="/blog/images/20191012115957375.jpg" alt="第一步"></li>
<li>运行 graphlab.get_dependencies()<br><img src="/blog/images/20191012124505697.jpg" alt="第二步"></li>
<li>再次执行import graphlab，即可成功，如下图：<br><img src="/blog/images/20191012120214550.jpg" alt="第三步"></li>
</ol>
<h3 id="Error-‘module’-object-has-no-attribute-‘SFrame’"><a href="#Error-‘module’-object-has-no-attribute-‘SFrame’" class="headerlink" title="Error: ‘module’ object has no attribute ‘SFrame’"></a>Error: ‘module’ object has no attribute ‘SFrame’</h3><p>使用SFrame时，报如下错误：<br><img src="/blog/images/20191012124949811.jpg" alt="使用SFrame报错"></p>
<p>错误原因： 使用了graphlab.get_dependencies()这句代码安装了某些内容<br>解决办法： 重启kernel来关闭这个文件即可</p>
<h3 id="Error-UnicodeEncodeError-‘ascii’-codec-can’t-encode-characters"><a href="#Error-UnicodeEncodeError-‘ascii’-codec-can’t-encode-characters" class="headerlink" title="Error: UnicodeEncodeError: ‘ascii’ codec can’t encode characters"></a>Error: UnicodeEncodeError: ‘ascii’ codec can’t encode characters</h3><p>错误原因：Python2.X自然调用ascii编码解码程序去处理字符流，当字符流不属于ascii范围内，就会抛出异常（ordinal not in range(128)）。所以解决方法就是修改默认编码，需要注意的是需要先调用reload方法。<br>解决办法： s使用如下语句修改默认编码即可</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">import sys</span><br><span class="line"><span class="function"><span class="title">reload</span><span class="params">(sys)</span></span></span><br><span class="line">sys.setdefaultencoding( <span class="string">"utf-8"</span> )</span><br></pre></td></tr></table></figure>

<p><img src="/blog/images/20191012130016458.jpg" alt="使用SFrame报错"></p>
<h2 id="GraphLab-Create的使用"><a href="#GraphLab-Create的使用" class="headerlink" title="GraphLab Create的使用"></a>GraphLab Create的使用</h2><h3 id="SFrame的使用"><a href="#SFrame的使用" class="headerlink" title="SFrame的使用"></a>SFrame的使用</h3><p><img src="/blog/images/20191012063817663.jpg" alt="GraphLab Create的使用"><br><img src="/blog/images/20191012063951164.jpg" alt="SFrame的使用"></p>
<figure class="highlight maxima"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 从本地硬盘上读取数据文件</span><br><span class="line"><span class="built_in">sf</span> = gl.SFrame('./people-<span class="built_in">example</span>.csv')</span><br><span class="line"><span class="built_in">sf</span> # 显示<span class="built_in">sf</span>的所有数据</span><br><span class="line"><span class="built_in">sf</span>.head # 获取<span class="built_in">sf</span>数据的前<span class="number">7</span>行</span><br><span class="line"><span class="built_in">sf</span>.tail # 获取<span class="built_in">sf</span>数据的最后<span class="number">7</span>行</span><br></pre></td></tr></table></figure>

<h3 id="GraphLab-Canvas的使用"><a href="#GraphLab-Canvas的使用" class="headerlink" title="GraphLab Canvas的使用"></a>GraphLab Canvas的使用</h3><ol>
<li><p>显示GraphLab Canvas<br><img src="/blog/images/20191012134839062.jpg" alt="显示GraphLab Canvas"></p>
</li>
<li><p>使用上述命令，展示的GraphLab Canvas是在新页面中打开，如果想在本页面打开，使用如下方式：<br><img src="/blog/images/20191012135207409.jpg" alt="显示GraphLab Canvas"></p>
</li>
</ol>
<h3 id="SFrame中的列操作"><a href="#SFrame中的列操作" class="headerlink" title="SFrame中的列操作"></a>SFrame中的列操作</h3><figure class="highlight vala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># 获取某一列数据</span></span><br><span class="line">sf[<span class="string">'sex'</span>]</span><br><span class="line"><span class="meta"># 取平均值</span></span><br><span class="line">sf[<span class="string">'tel'</span>].mean()</span><br><span class="line"><span class="meta"># 取最大值</span></span><br><span class="line">sf[<span class="string">'tel'</span>].max()</span><br><span class="line"><span class="meta"># 增加新列</span></span><br><span class="line">sf[<span class="string">'fullname'</span>] = sf[<span class="string">'firstname'</span>] + <span class="string">' '</span> + sf[<span class="string">'lastname'</span>]</span><br><span class="line"><span class="meta"># 列运算</span></span><br><span class="line">sf[<span class="string">'age'</span>] + <span class="number">2</span></span><br><span class="line">sf[<span class="string">'age'</span>] * sf[<span class="string">'age'</span>]</span><br></pre></td></tr></table></figure>

<p><img src="/blog/images/20191012140111818.jpg" alt="SFrame中的列操作"></p>
<h3 id="SFrame中的apply函数"><a href="#SFrame中的apply函数" class="headerlink" title="SFrame中的apply函数"></a>SFrame中的apply函数</h3><blockquote>
<p>应用apply函数来转换数据</p>
</blockquote>
<p>如下例，USA和United States都表示美国，需要将他们改为一个名称，便于统计数据<br><img src="/blog/images/20191012140716113.jpg" alt="应用apply函数来转换数据"></p>
<ol>
<li><p>定义一个转换函数<br><img src="/blog/images/20191012142219785.jpg" alt="定义一个转换函数"></p>
</li>
<li><p>通过apply函数使用这个转换函数<br><img src="/blog/images/20191012142348128.jpg" alt="定义一个转换函数"></p>
</li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/机器学习启蒙/" rel="tag"># 机器学习启蒙</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2019/10/10/vue-learning-step-by-step-12/" rel="next" title="【实战篇——第十章】Vue2.5入门到实战开发去哪儿网App——项目的联调，测试与发布上线">
                <i class="fa fa-chevron-left"></i> 【实战篇——第十章】Vue2.5入门到实战开发去哪儿网App——项目的联调，测试与发布上线
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/10/11/machine-learning-step-by-step-2/" rel="prev" title="【第二章】机器学习启蒙——回归模型理论">
                【第二章】机器学习启蒙——回归模型理论 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">aiolos</p>
              <p class="site-description motion-element" itemprop="description">Java Spring Hadoop 机器学习</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">126</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#课程介绍"><span class="nav-number">1.</span> <span class="nav-text">课程介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#教学方法"><span class="nav-number">2.</span> <span class="nav-text">教学方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#机器学习管道"><span class="nav-number">3.</span> <span class="nav-text">机器学习管道</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#课程内容"><span class="nav-number">4.</span> <span class="nav-text">课程内容</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#机器学习的应用"><span class="nav-number">5.</span> <span class="nav-text">机器学习的应用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GraphLab-Create的安装"><span class="nav-number">6.</span> <span class="nav-text">GraphLab Create的安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#出现Error-environment-does-not-exist错误的安装方法"><span class="nav-number">6.1.</span> <span class="nav-text">出现Error: environment does not exist错误的安装方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#import-graphlab错误"><span class="nav-number">6.2.</span> <span class="nav-text">import graphlab错误</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Error-‘module’-object-has-no-attribute-‘SFrame’"><span class="nav-number">6.3.</span> <span class="nav-text">Error: ‘module’ object has no attribute ‘SFrame’</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Error-UnicodeEncodeError-‘ascii’-codec-can’t-encode-characters"><span class="nav-number">6.4.</span> <span class="nav-text">Error: UnicodeEncodeError: ‘ascii’ codec can’t encode characters</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GraphLab-Create的使用"><span class="nav-number">7.</span> <span class="nav-text">GraphLab Create的使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#SFrame的使用"><span class="nav-number">7.1.</span> <span class="nav-text">SFrame的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#GraphLab-Canvas的使用"><span class="nav-number">7.2.</span> <span class="nav-text">GraphLab Canvas的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SFrame中的列操作"><span class="nav-number">7.3.</span> <span class="nav-text">SFrame中的列操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SFrame中的apply函数"><span class="nav-number">7.4.</span> <span class="nav-text">SFrame中的apply函数</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">aiolos</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
